package cn.ekuma.epos.datalogic.define.dao.crm;

import e.odbo.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.crm.I_CustomerContact;

import com.openbravo.bean.BusinessPartner;
import com.openbravo.bean.crm.CustomerContact;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class CustomerContactDAO extends ModifiedLogDAO<CustomerContact>{

    public CustomerContactDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                    "CUSTOMER_CONTACT",
                    new Field[]{
                       new Field(I_CustomerContact.ID,Datas.STRING, Formats.STRING),
                       new Field(I_CustomerContact.CONTACT_TIME,Datas.TIMESTAMP, Formats.TIMESTAMP),
                       new Field(I_CustomerContact.CONTACT_TYPE,Datas.STRING, Formats.STRING),
                       new Field(I_CustomerContact.PRIORITY,Datas.STRING, Formats.STRING),
                       new Field(I_CustomerContact.USER,Datas.STRING, Formats.STRING),
                       new Field(I_CustomerContact.MEMO,Datas.STRING, Formats.STRING),
                       new Field(I_CustomerContact.RESULT,Datas.STRING, Formats.STRING),
                       new Field(I_CustomerContact.FOLLOW_UP_TIME,Datas.TIMESTAMP, Formats.TIMESTAMP),
                       new Field(I_CustomerContact.CUSTOMER_USER,Datas.STRING, Formats.STRING),
                       new Field(I_CustomerContact.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP),
                       new Field(I_CustomerContact.CUSTOMER_ID,Datas.STRING, Formats.STRING,BusinessPartner.class)
                     },
                    new int[]{0}
                    );
    }

	@Override
	public void writeInsertValues(DataWrite dp, CustomerContact obj)
			throws BasicException {
		dp.setString(1,obj.getId());
		dp.setTimestamp(2,obj.getContactTime());
		dp.setString(3,obj.getContactType());
		dp.setInt(4,obj.getPriority());
		dp.setString(5,obj.getUser());
		dp.setString(6,obj.getMemo());
		dp.setString(7,obj.getResult());
		dp.setTimestamp(8,obj.getFollowUpTime());
		dp.setString(9,obj.getCustomerUser());
		dp.setTimestamp(10,obj.getLastModified());
		dp.setString(11,obj.getCustomerId());
		
	}

	@Override
	public Class getSuportClass() {
		return CustomerContact.class;
	}

	@Override
	public CustomerContact readValues(DataRead dr, CustomerContact obj)
			throws BasicException {
		if(obj==null)
			obj=new CustomerContact();
		obj.setId(dr.getString(1));
		obj.setContactTime(dr.getTimestamp(2));
		obj.setContactType(dr.getString(3));
		obj.setPriority(dr.getInt(4));
		obj.setUser(dr.getString(5));
		obj.setMemo(dr.getString(6));
		obj.setResult(dr.getString(7));
		obj.setFollowUpTime(dr.getTimestamp(8));
		obj.setCustomerUser(dr.getString(9));
		obj.setLastModified(dr.getTimestamp(10));
		obj.setCustomerId(dr.getString(11));
		return obj;
	}

}
